import axios from 'axios'

export interface Book {
  id: number
  title: string
  author: string
  price: number
  cover: string
  description: string
  createdAt: string
}

export interface PageRequest {
  page: number
  size: number
  sort?: string
}

export interface PageResponse<T> {
  content: T[]
  totalElements: number
  totalPages: number
  size: number
  number: number
}

// 获取图书列表
export const getBooks = async (params: PageRequest): Promise<PageResponse<Book>> => {
  const response = await axios.get('/api/books', { params })
  return response.data
}

// 获取图书详情
export const getBook = async (id: number): Promise<Book> => {
  const response = await axios.get(`/api/books/${id}`)
  return response.data
}

export const uploadBookCover = (data: FormData) => {
  return request({
    url: '/books/upload',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
} 